package com.snake.test.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.snake.mylibrary.base.BaseActivity;
import com.snake.test.R;

import java.util.ArrayList;

public class ListViewMultiItemActivity extends BaseActivity {

    private ListView mListView;
    private ArrayList<String> mData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_list_view_mult_item);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        mListView = (ListView) findViewById(R.id.listView);
    }

    @Override
    protected void initData() {

        mData = new ArrayList<>();
        for (int i=0;i<20;i++){
            mData.add("数据"+i);
        }

        mListView.setAdapter(new MyAdapter());
    }

    @Override
    protected void initListener() {

    }

    class MyAdapter extends BaseAdapter{


        @Override
        public int getCount() {
            return mData.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            if(position%2==0){
                View view1 = View.inflate(ListViewMultiItemActivity.this, R.layout.listview_item1, null);
               return view1;
            }

            if(position%2==1){
                View view2 = View.inflate(ListViewMultiItemActivity.this, R.layout.listview_item2, null);
                return view2;
            }
            return null;
        }


    }

}
